package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("UserOderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "C端-订单接口")
public class OrderController {
    @Autowired
    OrderService orderService;


    @ApiOperation("用户下单接口")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单："+ordersSubmitDTO.toString());
        return Result.success(orderService.submit(ordersSubmitDTO));
    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
    @GetMapping("/historyOrders")
    @ApiOperation("历史订单")
    public Result<PageResult> historyOrder(Integer page,Integer pageSize,Integer status) throws Exception {
        return Result.success(orderService.page(page,pageSize,status));
    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("订单详细")
    public Result<OrderVO> orderDetail(@PathVariable Long id) throws Exception {
        return Result.success(orderService.detail(id));
    }
    @PutMapping("cancel/{id}")
    @ApiOperation("订单取消")
    public Result ordercancenl(@PathVariable Long id) throws Exception {
        orderService.cancel(id);
        return Result.success();
    }
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来订单")
    public Result again(@PathVariable Long id)  {
        orderService.again(id);
        return Result.success();
    }
    @GetMapping("/reminder/{id}")
    @ApiOperation("cui单")
    public Result reminder(@PathVariable Long id)  {
        orderService.reminder(id);
        return Result.success();
    }

}
